package academic.ui.client.widgets;

import ui.client.GenericContainerTag;

import academic.ui.client.util.ClientHelper;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;

import ecommerce.soco.shared.GWT_Product;

public class BoughtPriceDiv extends Composite {

	GenericContainerTag div1 = new GenericContainerTag("div");
	
	public BoughtPriceDiv(GWT_Product product) {
		GenericContainerTag boughtDiv = new GenericContainerTag("div");
		GenericContainerTag priceDiv = new GenericContainerTag("div");
		Image priceTagImg = new Image(GWT.getModuleBaseURL()+"images/small_price_tag.png");
		GenericContainerTag unitPrice = new GenericContainerTag("span");
		GenericContainerTag keyPrice = new GenericContainerTag("span","Price:");
		GenericContainerTag price = new GenericContainerTag("span",ClientHelper.formatPriceNoDecimal(product.getPrice0()));
		GenericContainerTag valueKey = new GenericContainerTag("span","Value:");
		GenericContainerTag valuePrice = new GenericContainerTag("span",ClientHelper.formatPriceNoDecimal(product.getPrice1()));
		GenericContainerTag savingsKey = new GenericContainerTag("span","Savings:");
		GenericContainerTag	savingsValue = new GenericContainerTag("span",ClientHelper.formatPriceNoDecimal(product.getPrice1()-product.getPrice0()));
		GenericContainerTag valueSpan = new GenericContainerTag("span");
		GenericContainerTag savingsSpan = new GenericContainerTag("span");
		GenericContainerTag quantitySpan = new GenericContainerTag("span",String.valueOf(product.getNumPurchased()!=null?product.getNumPurchased():"0"));
		GenericContainerTag logoBoughtSpan = new GenericContainerTag("span","socodeals bought");
		
		unitPrice.add(keyPrice);
		unitPrice.add(price);
		
		valueSpan.add(valueKey);
		valueSpan.add(valuePrice);
		savingsSpan.add(savingsKey);
		savingsSpan.add(savingsValue);
		priceDiv.add(priceTagImg);
		priceDiv.add(unitPrice);
		priceDiv.add(valueSpan);
		priceDiv.add(savingsSpan);
		
		boughtDiv.add(quantitySpan);
		boughtDiv.add(logoBoughtSpan);
		div1.add(boughtDiv);
		div1.add(priceDiv);
		div1.setStyleName("boughtPriceDiv");
		boughtDiv.setStyleName("bought");
		quantitySpan.setStyleName("quantity");
		priceDiv.setStyleName("price");
		priceTagImg.setStyleName("price_tag");
		unitPrice.setStyleName("unit_price");
		keyPrice.setStyleName("key");
		price.setStyleName("value");
		valueKey.setStyleName("key");
		valuePrice.setStyleName("value");
		savingsKey.setStyleName("key");
		savingsValue.setStyleName("value");
		
		initWidget(div1);
	}
}
